;;==========================================================================
;; Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
;;==========================================================================

#include <regs.h>
#include "syscallno.h"

#define DO_SYSCALL(parameter, syscallno)    \
    li      v1, parameter;                  \
    li      v0, syscallno;                  \
    syscall;

//
// SYSCALLAPI ECode SysPrint(const wchar_t * pwszMsg)
//
LEAF(SysPrint)
    DO_SYSCALL(1, CALLNO_SYS_PRINT);
    jr      ra;
END(SysPrint)




//
// SYSCALLAPI ECode SysGetMemtraceArgs(wchar_t *pwchArgId, UInt32 *pIndex, \
//                                        Address *pWatchAddr)
//
LEAF(SysGetMemtraceArgs)
    DO_SYSCALL(3, CALLNO_SYS_GETMEMTRACEARGS);
    jr      ra;
END(SysGetMemtraceArgs)




//
// SYSCALLAPI ECode SysBreak(uint_t uAddr)
//
LEAF(SysBreak)
    DO_SYSCALL(1, CALLNO_SYS_BREAK);
    jr      ra;
END(SysBreak)




//
// SYSCALLAPI ECode SysRegister(IStub *pIStub, CLSID *pCLSID, IID * pIID, \
//                               oid_t *pOid, CIClassEntry ** ppClsInfo)
//
LEAF(SysRegister)
    DO_SYSCALL(5, CALLNO_SYS_REGISTER);
    jr      ra;
END(SysRegister)




//
// SYSCALLAPI ECode SysUnregister(oid_t oid)
//
LEAF(SysUnregister)
    DO_SYSCALL(1, CALLNO_SYS_UNREGISTER);
    jr      ra;
END(SysUnregister)




//
// SYSCALLAPI ECode SysRegisterCommon(const wchar_t * pwszName, \
//            IStub * pIStub, CLSID * pCLSID, IID * pIID,\
//            oid_t * pRet, CIClassEntry ** ppClsInfo)
//
LEAF(SysRegisterCommon)
    addiu   sp, sp, -0x20;
    sw      a2, 0x18(sp);
    sw      a3, 0x1c(sp);
    addiu   a2, sp, 0x18;
    lw      a3, 0x30(sp);
    lw      v0, 0x34(sp);
    sw      v0, 0x10(sp);
    DO_SYSCALL(5, CALLNO_SYS_REGISTER_COMMON);
    addiu   sp, sp, 0x20;
    jr      ra;
END(SysRegisterCommon)




//
// SYSCALLAPI ECode SysResolveCommon(const wchar_t * pwszName, oid_t * pRet, \
//                      CLSID *pClsid, UInt32 *puIndex, CIClassEntry ** ppClsInfo, \
//                      PContext * ppContext)
//
LEAF(SysResolveCommon)
    addiu   sp, sp, -0x20;
    lw      v0, 0x30(sp);
    sw      v0, 0x18(sp);
    lw      v1, 0x34(sp);
    sw      v1, 0x1c(sp);
    addiu   v0, sp, 0x18;
    sw      v0, 0x10(sp);
    DO_SYSCALL(5, CALLNO_SYS_RESOLVE_COMMON);
    addiu   sp, sp, 0x20;
    jr      ra;
END(SysResolveCommon)




//
// SYSCALLAPI ECode SysUnregisterCommon(const wchar_t * pwszName)
//
LEAF(SysUnregisterCommon)
    DO_SYSCALL(1, CALLNO_SYS_UNREGISTER_COMMON);
    jr      ra;
END(SysUnregisterCommon)




//
// SYSCALLAPI ECode SysInvoke(oid_t oid, bool_t async, void *pvInBuf,
//            size_t uInBufSize, void *pvOutBuf, size_t uOutBufSize)
//
LEAF(SysInvoke)
    addiu   sp, sp, -0x20;
    sw      a0, 0x18(sp);
    sw      a1, 0x1c(sp);
    addiu   a0, sp, 0x18;
    or      a1, a2, zero;
    or      a2, a3, zero;
    lw      a3, 0x30(sp);
    lw      v0, 0x34(sp);
    sw      v0, 0x10(sp);
    DO_SYSCALL(5, CALLNO_SYS_INVOKE);
    addiu   sp, sp, 0x20;
    jr      ra;
END(SysInvoke)



//
// SYSCALLAPI ECode SysReply(ECode ec,
//            void *pvOutBuf, size_t uOutBufSize)
//
LEAF(SysReply)
    DO_SYSCALL(3, CALLNO_SYS_REPLY);
    jr      ra;
END(SysReply)



//
// SYSCALLAPI ECode SysRegisterClassInfo(CIClassInfo * pClassInfo)
//
LEAF(SysRegisterClassInfo)
    DO_SYSCALL(1, CALLNO_SYS_REGISTER_CLASS_INFO);
    jr      ra;
END(SysRegisterClassInfo)



//
// SYSCALLAPI ECode SysGetClassInfo(CLSID *pClsid, CIClassEntry **ppClassInfo)
//
LEAF(SysGetClassInfo)
    DO_SYSCALL(2, CALLNO_SYS_GET_CLASS_INFO);
    jr      ra;
END(SysGetClassInfo)



//
// SYSCALLAPI ECode SysExitThread(
//       /* [in] */ ECode exitCode)
LEAF(SysExitThread)
    DO_SYSCALL(1, CALLNO_SYS_EXIT_THREAD);
    jr      ra;
END(SysExitThread)




//
// SYSCALLAPI ECode SysRegisterService(const wchar_t * pwszName, OID oid)
//
LEAF(SysRegisterService)
    DO_SYSCALL(2, CALLNO_SYS_REGISTER_SERVICE);
    jr      ra;
END(SysRegisterService)

//
// SYSCALLAPI ECode SysWaitService(const wchar_t * pwszName, Int32 msTimeout)
//
LEAF(SysWaitService)
    DO_SYSCALL(2, CALLNO_SYS_WAIT_SERVICE);
    jr      ra;
END(SysWaitService)


//
// SYSCALLAPI ECode SysAttachServer(OID oid, PContext pContext)
//
LEAF(SysAttachServer)
    DO_SYSCALL(2, CALLNO_SYS_ATTACH_SERVER);
    jr      ra;
END(SysAttachServer)



//
// SYSCALLAPI ECode SysDetachServer(OID oid, PContext pContext)
//
LEAF(SysDetachServer)
    DO_SYSCALL(2, CALLNO_SYS_DETACH_SERVER);
    jr      ra;
END(SysDetachServer)



//
//SYSCALLAPI ECode SysCreateEvent(HANDLE *pEventHandle)
//
LEAF(SysCreateEvent)
    DO_SYSCALL(1, CALLNO_SYS_CREATE_EVENT);
    jr      ra;
END(SysCreateEvent)




//
// SYSCALLAPI ECode SysDestroyEvent(HANDLE eventHandle)
//
LEAF(SysDestroyEvent)
    DO_SYSCALL(1, CALLNO_SYS_DESTROY_EVENT);
    jr      ra;
END(SysDestroyEvent)




//
// SYSCALLAPI ECode SysNotifyEvent(HANDLE eventHandle)
//
LEAF(SysNotifyEvent)
    DO_SYSCALL(1, CALLNO_SYS_NOTIFY_EVENT);
    jr      ra;
END(SysNotifyEvent)




//
// SYSCALLAPI ECode SysWaitEvent(HANDLE eventHandle)
//
LEAF(SysWaitEvent)
    DO_SYSCALL(1, CALLNO_SYS_WAIT_EVENT);
    jr      ra;
END(SysWaitEvent)




//
// SYSCALLAPI ECode SysSetBreakPoint(
//        UInt32 uNo, BreakPointType type, void *pvAddress, UInt32 uLength)
//
LEAF(SysSetBreakPoint)
    DO_SYSCALL(4, CALLNO_SYS_SET_BREAKPOINT);
    jr      ra;
END(SysSetBreakPoint)


//
// SYSCALLAPI ECode SysGetVirtualCode(struct KBDStatus *pVirtulCode)
//
LEAF(SysGetVirtualCode)
    DO_SYSCALL(1, CALLNO_SYS_GETVIRTUALCODE);
    jr      ra;
END(SysGetVirtualCode)




//
// SYSCALLAPI ECode SysReboot()
//
LEAF(SysReboot)
    DO_SYSCALL(0, CALLNO_SYS_SYSREBOOT);
    jr      ra;
END(SysReboot)
